#!/usr/bin/env python3
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Match objects.
"""

#end_pymotw_header
import re

pattern = 'this'
text = 'Does this text match the pattern?'

# 若搜索到，则返回match对象，否则返回None
match = re.search(pattern, text)

# match对象还是包含了很多东西的
# 这是匹配到的字串的开始和结束索引
s = match.start()
e = match.end()

# match对象还包含了匹配的正则表达式，还有string
print('Found "{}"\nin "{}"\nfrom {} to {} ("{}")'.format(
    match.re.pattern, match.string, s, e, text[s:e]))
